﻿@model PageVM
@if (Model.Pag.PageTotal > 1)
{
    <ul class="pagination justify-content-center">
        @if (Model.Pag.PageNumber > 1)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber - 1)">
                    <span>&laquo;</span>
                </a>
            </li>
        }
        @if (Model.Pag.PageNumber > 3)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(1)">1</a>
            </li>
            @if (Model.Pag.PageNumber - 3 > 2)
            {
                <li class="page-item disabled">
                    <a class="page-link">...</a>
                </li>
            }
            else if (Model.Pag.PageNumber - 3 == 2)
            {
                <li class="page-item">
                    <a class="page-link" href="@Model.Page(2)">2</a>
                </li>
            }
        }
        @if (Model.Pag.PageNumber - 2 > 0)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber - 2)">
                    @(Model.Pag.PageNumber - 2)
                </a>
            </li>
        }
        @if (Model.Pag.PageNumber - 1 > 0)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber - 1)">
                    @(Model.Pag.PageNumber - 1)
                </a>
            </li>
        }

        <li class="page-item active"><a class="page-link" href="@Model.Page(Model.Pag.PageNumber)">@Model.Pag.PageNumber</a></li>

        @if (Model.Pag.PageNumber + 1 <= Model.Pag.PageTotal)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber + 1)">
                    @(Model.Pag.PageNumber + 1)
                </a>
            </li>
        }
        @if (Model.Pag.PageNumber + 2 <= Model.Pag.PageTotal)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber + 2)">
                    @(Model.Pag.PageNumber + 2)
                </a>
            </li>
        }
        @if (Model.Pag.PageNumber + 3 <= Model.Pag.PageTotal)
        {
            if (Model.Pag.PageNumber + 3 < Model.Pag.PageTotal - 1)
            {
                <li class="page-item disabled">
                    <a class="page-link">...</a>
                </li>
            }
            else if (Model.Pag.PageNumber + 3 == Model.Pag.PageTotal - 1)
            {
                <li class="page-item">
                    <a class="page-link" href="@Model.Page(Model.Pag.PageTotal-1)">
                        @(Model.Pag.PageTotal - 1)
                    </a>
                </li>
            }
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageTotal)">
                    @Model.Pag.PageTotal
                </a>
            </li>
        }
        @if (Model.Pag.PageNumber < Model.Pag.PageTotal)
        {
            <li class="page-item">
                <a class="page-link" href="@Model.Page(Model.Pag.PageNumber + 1)">
                    <span>&raquo;</span>
                </a>
            </li>
        }
    </ul>
}